﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace App1
{
    class Cannon: Pieces
    {
        public override bool CheckLegalMove(int row, int col)
        {
            bool legal = false;
            //Side 1 , Side 2
            int count = 0;
            if (row == _row)
            {
                int t = -1;
                int n = 0;
                if (col < _col)
                {
                    t = col;
                    n = _col;
                }
                else
                {
                    t = _col;
                    n = col;
                }
                for (int i = t + 1; i < n; ++i)
                    if (Board.Square[_row, i].State)
                        ++count;
                if (count == 1)
                    if (Board.Square[row, col].State && Board.Square[row, col].Side != _side)
                        legal = true;
                if (count == 0 && !Board.Square[row, col].State)
                    legal = true;
            }

            if (col == _col)
            {
                int t = -1;
                int n = 0;
                if (row < _row)
                {
                    t = row;
                    n = _row;
                }
                else
                {
                    t = _row;
                    n = row;
                }
                for (int i = t + 1; i < n; ++i)
                    if (Board.Square[i, _col].State)
                    {
                        ++count;
                    }
                if (count == 1 && Board.Square[row, col].State && Board.Square[row, col].Side != _side)
                    legal = true;
                if (count == 0 && !Board.Square[row, col].State)
                    legal = true;
            }
            return legal;
        }

        public override bool CheckSafeOfKing(int row, int col)
        {
            return true;
        }
    }
}
